package com.ruoyi.business.service.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.business.domain.Laserpowerdetectorhis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ActuatorhnchisMapper;
import com.ruoyi.business.domain.Actuatorhnchis;
import com.ruoyi.business.service.IActuatorhnchisService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author DL
 * @date 2025-07-08
 */
@Service
public class ActuatorhnchisServiceImpl implements IActuatorhnchisService 
{
    @Autowired
    private ActuatorhnchisMapper actuatorhnchisMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param ID 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public Actuatorhnchis selectActuatorhnchisByID(Long ID)
    {
        return actuatorhnchisMapper.selectActuatorhnchisByID(ID);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param actuatorhnchis 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<Actuatorhnchis> selectActuatorhnchisList(Actuatorhnchis actuatorhnchis)
    {
        return actuatorhnchisMapper.selectActuatorhnchisList(actuatorhnchis);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param actuatorhnchis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertActuatorhnchis(Actuatorhnchis actuatorhnchis)
    {
        return actuatorhnchisMapper.insertActuatorhnchis(actuatorhnchis);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param actuatorhnchis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateActuatorhnchis(Actuatorhnchis actuatorhnchis)
    {
        return actuatorhnchisMapper.updateActuatorhnchis(actuatorhnchis);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param IDs 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteActuatorhnchisByIDs(Long[] IDs)
    {
        return actuatorhnchisMapper.deleteActuatorhnchisByIDs(IDs);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param ID 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteActuatorhnchisByID(Long ID)
    {
        return actuatorhnchisMapper.deleteActuatorhnchisByID(ID);
    }

    @Override
    public Map<String, Object> getActuatorhnchisDataBetween(LocalDateTime startTime, LocalDateTime endTime) {
        // 查询数据库获取数据
        List<Actuatorhnchis> dataList = actuatorhnchisMapper.findByTimestampBetween(startTime, endTime);

        // 处理数据格式
        Map<String, Object> result = new HashMap<>();
        String[] xdata = new String[dataList.size()];
        double[] AxisXCurrent = new double[dataList.size()];
        double[] AxisYCurrent = new double[dataList.size()];
        double[] AxisZCurrent = new double[dataList.size()];
        double[] AxisBCurrent = new double[dataList.size()];
        double[] AxisCCurrent = new double[dataList.size()];

        // 定义格式化器
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

        for (int i = 0; i < dataList.size(); i++) {
            Actuatorhnchis data = dataList.get(i);
            xdata[i] = sdf.format(data.getEventTime());
            AxisXCurrent[i] = data.getAxisXCurrent() != null ? data.getAxisXCurrent().doubleValue() : 0.0;
            AxisYCurrent[i] = data.getAxisYCurrent() != null ? data.getAxisYCurrent().doubleValue() : 0.0;
            AxisZCurrent[i] = data.getAxisZCurrent() != null ? data.getAxisZCurrent().doubleValue() : 0.0;
            AxisBCurrent[i] = data.getAxisBCurrent() != null ? data.getAxisBCurrent().doubleValue() : 0.0;
            AxisCCurrent[i] = data.getAxisCCurrent() != null ? data.getAxisCCurrent().doubleValue() : 0.0;
        }

        result.put("xdata", xdata);
        result.put("AxisXCurrent", AxisXCurrent);
        result.put("AxisYCurrent", AxisYCurrent);
        result.put("AxisZCurrent", AxisZCurrent);
        result.put("AxisBCurrent", AxisBCurrent);
        result.put("AxisCCurrent", AxisCCurrent);

        return result;
    }
}
